package www.dashu.com.domain;

import www.dashu.com.domain.base.BaseVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Formula;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name="c_product")
public class CProduct extends BaseVo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("")
    @Id
    private Long id;

    @ApiModelProperty("品牌")
    @Column(name = "brand_id")
    private Long brandId;

    @Formula("(select s.name from c_brand s where s.id = brand_id )")
    private String brandName;

    @ApiModelProperty("分类")
    @Column(name = "product_category_id")
    private Long productCategoryId;

    @Formula("(select s.name from c_product_category s where s.id = product_category_id )")
    private String productCategoryName;

    @Formula("(select s.parent_id from c_product_category s where s.id = product_category_id )")
    private Long productCategoryParentId;

    @Formula("(select s.name from c_product_category s where s.id = (select s1.parent_id from c_product_category s1 where s1.id = product_category_id ) )")
    private String productCategoryParentName;

    @ApiModelProperty("属性类别")
    @Column(name = "product_attribute_category_id")
    private Long productAttributeCategoryId;

    @Formula("(select s.name from c_product_attribute_category s where s.id = product_attribute_category_id )")
    private String productAttributeCategoryName;

    @ApiModelProperty("商品名")
    @Column(name = "name")
    private String name;

    @ApiModelProperty("封面图片")
    @Column(name = "pic")
    private String pic;

    @ApiModelProperty("删除状态：0->未删除；1->已删除")
    @Column(name = "delete_status")
    private Integer deleteStatus;

    @ApiModelProperty("上架状态：0->下架；1->上架")
    @Column(name = "publish_status")
    private Integer publishStatus;

    @ApiModelProperty("审核状态：0->未审核；1->审核通过")
    @Column(name = "verify_status")
    private Integer verifyStatus;

    @ApiModelProperty("销量")
    @Column(name = "sale")
    private Integer sale;

    @ApiModelProperty("价格")
    @Column(name = "price")
    private Double price;

    @ApiModelProperty("促销价格")
    @Column(name = "promotion_price")
    private Double promotionPrice;

    @ApiModelProperty("会员价")
    @Column(name = "hy_price")
    private Double hyPrice;

    @ApiModelProperty("副标题")
    @Column(name = "sub_title")
    private String subTitle;

    @ApiModelProperty("商品描述")
    @Column(name = "description")
    private String description;

    @ApiModelProperty("库存")
    @Column(name = "stock")
    private Integer stock;

    @ApiModelProperty("库存预警值")
    @Column(name = "low_stock")
    private Integer lowStock;

    @ApiModelProperty("单位")
    @Column(name = "unit")
    private String unit;

    @ApiModelProperty("商品重量，默认为克")
    @Column(name = "weight")
    private Double weight;

    @ApiModelProperty("是否为预告商品：0->不是；1->是")
    @Column(name = "preview_status")
    private Integer previewStatus;

    @ApiModelProperty("以逗号分割的产品服务：1->无忧退货；2->快速退款；3->免费包邮")
    @Column(name = "service_ids")
    private String serviceIds;

    @ApiModelProperty("画册图片，连产品图片限制为5张，以逗号分割")
    @Column(name = "album_pics")
    private String albumPics;

    @ApiModelProperty("详情描述")
    @Column(name = "detail_desc")
    private String detailDesc;

    @ApiModelProperty("产品详情网页内容")
    @Column(name = "detail_html")
    private String detailHtml;

    @ApiModelProperty("移动端网页详情")
    @Column(name = "detail_mobile_html")
    private String detailMobileHtml;

    @ApiModelProperty("促销开始时间")
    @Column(name = "promotion_start_time")
    private Date promotionStartTime;

    @ApiModelProperty("促销结束时间")
    @Column(name = "promotion_end_time")
    private Date promotionEndTime;

    @ApiModelProperty("活动限购数量")
    @Column(name = "promotion_per_limit")
    private Integer promotionPerLimit;

    @ApiModelProperty("促销类型：0->没有促销使用原价;1->使用促销价；2->使用会员价；3->使用阶梯价格；4->使用满减价格；5->限时购")
    @Column(name = "promotion_type")
    private Integer promotionType;

    @ApiModelProperty("所属商户")
    @Formula("(select s.name from sys_company s where s.id = company )")
    private String companyName;

    @Column(name = "company")
    private Long company;

    @ApiModelProperty("所属应用")
    @Formula("(select s.name from sys_app s where s.id = app_id )")
    private String appName;

    @Column(name = "app_id")
    private Long appId;

    @ApiModelProperty("创建时间")
    @Column(name = "create_time")
    private Date createTime;

    @ApiModelProperty("更新时间")
    @Column(name = "update_time")
    private Date updateTime;

    @Transient
    List<CProductAttribute> selectProductAttr;

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", brandId=").append(brandId);
        sb.append(", productCategoryId=").append(productCategoryId);
        sb.append(", productAttributeCategoryId=").append(productAttributeCategoryId);
        sb.append(", name=").append(name);
        sb.append(", pic=").append(pic);
        sb.append(", deleteStatus=").append(deleteStatus);
        sb.append(", publishStatus=").append(publishStatus);
        sb.append(", verifyStatus=").append(verifyStatus);
        sb.append(", sale=").append(sale);
        sb.append(", price=").append(price);
        sb.append(", promotionPrice=").append(promotionPrice);
        sb.append(", hyPrice=").append(hyPrice);
        sb.append(", subTitle=").append(subTitle);
        sb.append(", description=").append(description);
        sb.append(", stock=").append(stock);
        sb.append(", lowStock=").append(lowStock);
        sb.append(", unit=").append(unit);
        sb.append(", weight=").append(weight);
        sb.append(", previewStatus=").append(previewStatus);
        sb.append(", serviceIds=").append(serviceIds);
        sb.append(", albumPics=").append(albumPics);
        sb.append(", detailDesc=").append(detailDesc);
        sb.append(", detailHtml=").append(detailHtml);
        sb.append(", detailMobileHtml=").append(detailMobileHtml);
        sb.append(", promotionStartTime=").append(promotionStartTime);
        sb.append(", promotionEndTime=").append(promotionEndTime);
        sb.append(", promotionPerLimit=").append(promotionPerLimit);
        sb.append(", promotionType=").append(promotionType);
        sb.append(", company=").append(company);
        sb.append(", appId=").append(appId);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append("]");
        return sb.toString();
    }

}